Skip to content

feat(pm): add why command for dependency analysis#272

Merged
fengmk2 merged 1 commit intomainfrom
10-24-feat_pm_add_why_commands
Oct 30, 2025
Merged

feat(pm): add why command for dependency analysis#272
fengmk2 merged 1 commit intomainfrom
10-24-feat_pm_add_why_commands

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Oct 29, 2025

TL;DR

Added a new vite why command (with explain alias) that shows why a package is installed in your project by automatically adapting to the detected package manager (pnpm/npm/yarn).

What changed?

  • Added a new why command to the CLI that shows dependency relationships for specified packages
  • Implemented package manager-specific command resolution for pnpm, npm, and yarn
  • Added support for various output formats (JSON, long, parseable)
  • Implemented workspace filtering and dependency type filtering options
  • Added support for multiple packages (with graceful degradation for npm/yarn)
  • Created appropriate warning messages for unsupported features in specific package managers
  • Added comprehensive unit tests for command resolution

How to test?

# Basic usage
vite why react

# With JSON output
vite why react --json

# Multiple packages (works with pnpm)
vite why react react-dom

# Using the alias
vite explain lodash

# With workspace filtering
vite why react --filter app

# Recursive across workspaces
vite why react -r

# Check globally installed packages
vite why typescript -g

Why make this change?

This command helps developers understand dependency relationships, audit package usage, and debug dependency tree issues. Previously, users had to remember package manager-specific commands (pnpm why, npm explain, yarn why), but now they can use a single unified interface that automatically adapts to the detected package manager. This is especially useful in monorepos or when switching between projects with different package managers.

Copy link
Copy Markdown
Member Author

fengmk2 commented Oct 29, 2025

@fengmk2 fengmk2 changed the title feat(pm): add why commands feat(cli): add why command for dependency analysis Oct 29, 2025
@fengmk2 fengmk2 force-pushed the 10-24-feat_pm_add_why_commands branch from 8bc85e5 to 89b1746 Compare October 29, 2025 08:51
@fengmk2 fengmk2 changed the title feat(cli): add why command for dependency analysis feat(pm): add why command for dependency analysis Oct 29, 2025
@fengmk2 fengmk2 force-pushed the 10-24-feat_pm_add_why_commands branch from 89b1746 to f47b47c Compare October 30, 2025 01:52
Comment thread packages/cli/binding/src/cli.rs
@fengmk2 fengmk2 force-pushed the 10-24-feat_pm_add_why_commands branch 2 times, most recently from 8be19c4 to c64a1db Compare October 30, 2025 03:21
@fengmk2 fengmk2 marked this pull request as ready for review October 30, 2025 03:27
@fengmk2 fengmk2 requested review from Brooooooklyn, branchseer and Copilot and removed request for Copilot October 30, 2025 03:27
@fengmk2 fengmk2 self-assigned this Oct 30, 2025
Copilot AI review requested due to automatic review settings October 30, 2025 05:52
@fengmk2 fengmk2 force-pushed the 10-24-feat_pm_add_why_commands branch from c64a1db to 9e246ff Compare October 30, 2025 05:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a vite why command (with alias vite explain) that provides a unified interface for querying package dependencies across different package managers (pnpm, npm, yarn). The command automatically detects the package manager and translates the command to the appropriate syntax, supporting various options like JSON output, workspace filtering, and dependency type filtering.

  • Adds new why command to CLI that adapts to detected package manager (pnpm/npm/yarn)
  • Implements package manager-specific command resolution with feature detection and warnings
  • Adds comprehensive test coverage with snapshot tests for pnpm10, npm10, and yarn4

Reviewed Changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
rfcs/why-package-command.md Complete RFC documentation for the vite why command feature
packages/tools/src/utils.ts Adds regex to normalize npm registry domains in test output
packages/tools/src/tests/utils.spec.ts Test case for registry domain replacement
packages/tools/src/tests/snapshots/utils.spec.ts.snap Expected output snapshot for registry domain test
packages/global/snap-tests/command-why-* Comprehensive snapshot tests for why command across package managers
packages/cli/binding/src/commands/why.rs New WhyCommand implementation for CLI binding
packages/cli/binding/src/commands/mod.rs Module export for why command
packages/cli/binding/src/cli.rs CLI argument parsing and command dispatch for why
crates/vite_install/src/commands/why.rs Core implementation of why command with package manager resolution
crates/vite_install/src/commands/mod.rs Module export for why command in install crate
packages/global/snap-tests/cli-helper-message/snap.txt Updated help output to include why command
packages/cli/snap-tests/exit-non-zero-on-cmd-not-exists/snap.txt Updated error message to include why/explain in subcommands

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
Comment thread crates/vite_install/src/commands/why.rs
@fengmk2 fengmk2 force-pushed the 10-24-feat_pm_add_why_commands branch from 9e246ff to 6087892 Compare October 30, 2025 07:13
Comment thread crates/vite_install/src/commands/why.rs Outdated
Copilot AI review requested due to automatic review settings October 30, 2025 12:02
@fengmk2 fengmk2 force-pushed the 10-24-feat_pm_add_why_commands branch from 6087892 to 86831a0 Compare October 30, 2025 12:02
@fengmk2 fengmk2 requested a review from branchseer October 30, 2025 12:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/vite_install/src/commands/why.rs
Comment thread packages/tools/src/utils.ts
Comment thread crates/vite_install/src/commands/why.rs
@fengmk2 fengmk2 merged commit 452e374 into main Oct 30, 2025
16 checks passed
Copy link
Copy Markdown
Member Author

fengmk2 commented Oct 30, 2025

Merge activity

@fengmk2 fengmk2 deleted the 10-24-feat_pm_add_why_commands branch October 30, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants